/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewFlightDialog.java
 *
 * Created on 8.12.2011, 13:33:59
 */

package view;

import logic.business.DataEditor;

/**
 *
 * @author zhenia
 */
public class NewFlightDialog extends javax.swing.JDialog {
    private boolean result;
    /** Creates new form NewFlightDialog */
    public NewFlightDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    NewFlightDialog(DataEditor dataEditor) {
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cancel = new javax.swing.JButton();
        cost = new javax.swing.JTextField();
        length = new javax.swing.JTextField();
        ok = new javax.swing.JButton();
        code = new javax.swing.JTextField();
        lengthLabel = new javax.swing.JLabel();
        costLabel = new javax.swing.JLabel();
        codeLabel = new javax.swing.JLabel();
        airplane = new javax.swing.JComboBox();
        airline = new javax.swing.JComboBox();
        airplaneLabel = new javax.swing.JLabel();
        airlineLabel = new javax.swing.JLabel();
        route = new javax.swing.JComboBox();
        routeLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Flight");

        cancel.setText("Cancel");
        cancel.setName("cancel"); // NOI18N
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });

        cost.setName("cost"); // NOI18N

        length.setName("length"); // NOI18N
        length.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lengthActionPerformed(evt);
            }
        });

        ok.setText("OK");
        ok.setName("ok"); // NOI18N
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });

        code.setName("code"); // NOI18N
        code.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                codeActionPerformed(evt);
            }
        });

        lengthLabel.setText("Length");
        lengthLabel.setName("lengthLabel"); // NOI18N

        costLabel.setText("Price");
        costLabel.setName("costLabel"); // NOI18N

        codeLabel.setText("Code");
        codeLabel.setName("codeLabel"); // NOI18N

        airplane.setName("airplane"); // NOI18N

        airline.setName("airline"); // NOI18N
        airline.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                airlineActionPerformed(evt);
            }
        });

        airplaneLabel.setText("Airplane");
        airplaneLabel.setName("airplaneLabel"); // NOI18N

        airlineLabel.setText("Airline");
        airlineLabel.setName("airlineLabel"); // NOI18N

        route.setName("route"); // NOI18N

        routeLabel.setText("Route");
        routeLabel.setName("routeLabel"); // NOI18N

        jLabel1.setText("Kč");
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(260, Short.MAX_VALUE)
                .addComponent(ok)
                .addGap(18, 18, 18)
                .addComponent(cancel)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(airlineLabel)
                    .addComponent(airplaneLabel)
                    .addComponent(routeLabel)
                    .addComponent(lengthLabel)
                    .addComponent(costLabel)
                    .addComponent(codeLabel))
                .addGap(57, 57, 57)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(length)
                    .addComponent(code, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                    .addComponent(cost)
                    .addComponent(airline, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(airplane, 0, 64, Short.MAX_VALUE)
                    .addComponent(route, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addContainerGap(198, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(code, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(codeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(costLabel)
                    .addComponent(jLabel1))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(length, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lengthLabel))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(airlineLabel)
                    .addComponent(airline, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(airplaneLabel)
                    .addComponent(airplane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(routeLabel)
                    .addComponent(route, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ok)
                    .addComponent(cancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed

        // this.result = false;
        this.dispose();
        // TODO add your handling code here:
}//GEN-LAST:event_cancelActionPerformed

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
        // TODO add your handling code here:
        //   dataEditor.addNewRoute(null, "0", "0", "0", departureAirports.getSelectedItem(), arrivalAirports.getSelectedItem());
        //       System.out.println(departureAirports.getSelectedItem());
        //              System.out.println(arrivalAirports.getSelectedItem());
        //
        //        Airport departureAirport = null;
        //        Airport arrivalAirport=null;
        //        for(Airport a:airports){
        //            if(a.getName()==departureAirports.getSelectedItem())departureAirport= a;
        //        }
        //        for(Airport a:airports){
        //            if(a.getName()==arrivalAirports.getSelectedItem())arrivalAirport= a;
        //        }
        //        try {
        //            dataEditor.addNewRoute("0", "0", "0", "0", departureAirport.getId(), arrivalAirport.getId());
        //        } catch (MalformedDataException ex) {
        //            Logger.getLogger(NewRouteDialog.class.getName()).log(Level.SEVERE, null, ex);
        //        } catch (ConstraintException ex) {
        //            Logger.getLogger(NewRouteDialog.class.getName()).log(Level.SEVERE, null, ex);
        //        }

        //        this.result = true;
        this.dispose();
}//GEN-LAST:event_okActionPerformed

    private void codeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codeActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_codeActionPerformed

    private void airlineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_airlineActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_airlineActionPerformed

    private void lengthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lengthActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lengthActionPerformed

     boolean execute() {
         this.setVisible(true); // прорисовать дочернее окно; в данном месте выполнение программы приостановится, ожидая окончания работы пользователя (в нашем случае - функции dispose())
	        return this.result;
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox airline;
    private javax.swing.JLabel airlineLabel;
    private javax.swing.JComboBox airplane;
    private javax.swing.JLabel airplaneLabel;
    private javax.swing.JButton cancel;
    private javax.swing.JTextField code;
    private javax.swing.JLabel codeLabel;
    private javax.swing.JTextField cost;
    private javax.swing.JLabel costLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField length;
    private javax.swing.JLabel lengthLabel;
    private javax.swing.JButton ok;
    private javax.swing.JComboBox route;
    private javax.swing.JLabel routeLabel;
    // End of variables declaration//GEN-END:variables

   

}
